﻿using Puppy.Domain.Entities;
using Puppy.Reflection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace Puppy.ActorDb
{
    internal static class ActorDbContextHelper
    {
        public static IEnumerable<Type> GetEntityTypes(Type dbContextType)
        {
            return
                from property in dbContextType.GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.Instance)
                where
                    ReflectionHelper.IsAssignableToGenericType(property.PropertyType, typeof(IActorSet<>)) &&
                    typeof(IEntity).IsAssignableFrom(property.PropertyType.GenericTypeArguments[0])
                select property.PropertyType.GenericTypeArguments[0];
        }
    }
}
